#ifndef USERMANAGER_H
#define USERMANAGER_H

#include "singleton.h"
#include "userdata.h"

#include <QObject>

class UserManager : public QObject, public Singleton<UserManager>, public std::enable_shared_from_this<UserManager>
{
    Q_OBJECT

    friend class Singleton<UserManager>;

public:
    ~UserManager();

    void setToken(QString token);
    void setUserInfo(std::shared_ptr<UserInfo> user_info);

    int getUid() const;
    QString getName() const;
    QString getIcon();
    std::shared_ptr<UserInfo> getUserInfo();
    std::shared_ptr<FriendInfo> getFriendById(int uid);
    QVector<std::shared_ptr<ApplyInfo>> getApplyList();
    // 获取聊天列表的其中一页(一页最多展示CHAT_COUNT_PER_PAGE)
    QVector<std::shared_ptr<FriendInfo>> getConListPerPage();
    // 获取好友列表的其中一页(一页最多展示CHAT_COUNT_PER_PAGE)
    QVector<std::shared_ptr<FriendInfo>> getChatListPerPage();

    void appendApplyList(QJsonArray array);
    void appendFriendList(QJsonArray array);
    void appendFriendChatMsg(int friend_id, QVector<std::shared_ptr<TextChatData>> msgs);

    void addFriend(std::shared_ptr<AuthRsp> auth_rsp);
    void addFriend(std::shared_ptr<AuthInfo> auth_info);
    void addApplyList(std::shared_ptr<ApplyInfo> app);

    bool alreadyApply(int uid);
    bool isLoadChatFinish();
    bool IsLoadContactFinish();
    void updateChatLoadedCount();
    void updateContactLoadedCount();

    // 检测添加的好友是否已近存在
    bool checkFriendById(int uid);

private:
    UserManager();

public slots:

signals:

private:
    QString m_token;
    int m_chat_loaded;
    int m_contact_loaded;
    std::shared_ptr<UserInfo> m_user_info;
    QVector<std::shared_ptr<ApplyInfo>> m_apply_list;
    QVector<std::shared_ptr<FriendInfo>> m_friend_list;
    QMap<int, std::shared_ptr<FriendInfo>> m_friend_map;
};

#endif // USERMANAGER_H
